# -*- coding: utf-8 -*-
#Importamos funciones standars
import datetime
from django.shortcuts import render_to_response

#importamos nuestros propios modulos
from salones.clientes.models import Clientes
from models import Servicios, Turnos
from formularios import Fservicio, Fturno, FturnoFull
from clases import Semana, Agenda, Links
from choices import Horarios

# Create your views here.
def Vmenu(request):
	return render_to_response('turnos/menu.html', {'fecha':datetime.date.today()},)

def Vservices(request):
	if request.method == 'POST': pass #Se esta realizando una busqueda de clientes (Filtrar, clientes)
	else: S = Servicios.objects.all()
	return render_to_response('listado.html',{'subject':"Clientes",'elementos':S,},)

def Vnuevo_service(request):
	if request.method == 'POST':
		if Fservicio(request.POST).is_valid():
			Fservicio(request.POST).save()
			return render_to_response('save.html', {'accion': 'Creacion de cliente'})
		else: return render_to_response('form.html',{'form':Fservicio(request.POST),'title':"Crear Cliente"},)
	else: return render_to_response('form.html',{'form':Fservicio(),'title':"Crear Cliente"},)

def Vagenda(request,d, m, y):
	Fecha= datetime.datetime(int(y),int(m),int(d))
	A = Agenda(Semana(Fecha))
	return render_to_response('turnos/agenda.html',{'agenda':A.html, 'links':Links(Fecha)},)

def Vnuevo_turno(request,d,m,y,h,min):
	if request.method == 'POST':
		if Fturno(request.POST).is_valid():
			Turnos(cliente=Clientes.objects.get(id=int(request.POST["cliente"])),fecha=datetime.date(day=int(d),month=int(m),year=int(y)),hora=datetime.time(int(h),int(min)),servicio=Servicios.objects.get(id=int(request.POST["servicio"])),info=request.POST["info"]).save()
			return render_to_response('save.html', {'accion': 'Turno Asignado'})
		else: return render_to_response('form.html',{'form':Fturno(request.POST),'title':"Crear Cliente"},)
	else: return render_to_response('form.html',{'form':Fturno(),'title':"Crear Cliente"},)

def Vadd_turno(request):
	if request.method == 'POST':
		if FturnoFull(request.POST).is_valid():
			Turnos(FturnoFull(request.POST).save())
			return render_to_response('save.html', {'accion': 'Turno Asignado'})
		else: return render_to_response('form.html',{'form':FturnoFull(request.POST),'title':"Crear Cliente"},)
	else: return render_to_response('form.html',{'form':FturnoFull(),'title':"Crear Cliente"},)